package com.digitalchina.lxnsy.viewholder;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.activity.mainConsult.ConsultEvaluateAddActivity;
import com.digitalchina.lxnsy.activity.mainConsult.ConsultEvaluateDetailActivity;
import com.digitalchina.lxnsy.activity.mainConsult.ImageViewActivity;
import com.digitalchina.lxnsy.entity.MainCosultVO;
import com.digitalchina.lxnsy.entity.MessageVO;
import com.digitalchina.lxnsy.toolkit.FrescoUtil;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.toolkit.JointImageUrl;
import com.digitalchina.lxnsy.xml.UserXML;
import com.facebook.drawee.view.SimpleDraweeView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：郑皓
 * 创建时间：2019/8/12 11:45:58
 * 修改备注：
 * ================================================
 */

public class ConsultDetailHolder extends BaseViewHolder<MessageVO> {


    SimpleDraweeView sdvHead1;
    TextView tvTime1;
    TextView tvMsg1;
    RelativeLayout layout1;
    SimpleDraweeView sdvHead2;
    TextView tvTime2;
    TextView tvMsg2;
    RelativeLayout layout2;
    TextView tvEvaluate;
    LinearLayout layout3;
    SimpleDraweeView sdvImg1;
    SimpleDraweeView sdvImg2;

    private MainCosultVO mainCosultVO;

    public ConsultDetailHolder(ViewGroup parent, MainCosultVO mainCosultVO) {
        super(parent, R.layout.item_consult_detail);

        sdvHead1 = $(R.id.sdv_head1);
        tvTime1 = $(R.id.tv_time1);
        tvMsg1 = $(R.id.tv_msg1);
        sdvImg1 = $(R.id.sdv_img1);
        layout1 = $(R.id.layout1);
        sdvHead2 = $(R.id.sdv_head2);
        tvTime2 = $(R.id.tv_time2);
        tvMsg2 = $(R.id.tv_msg2);
        sdvImg2 = $(R.id.sdv_img2);
        layout2 = $(R.id.layout2);
        layout3 = $(R.id.layout3);
        tvEvaluate = $(R.id.tv_evaluate);

        this.mainCosultVO = mainCosultVO;
    }

    @Override
    public void setData(final MessageVO data) {
        super.setData(data);


        //判断发送者是否为当前账号
        if (UserXML.getUserId(getContext()).equals(data.getSendUser())) {
            layout1.setVisibility(View.GONE);
            layout2.setVisibility(View.VISIBLE);
            tvTime2.setText(data.getCreateTime());
            FrescoUtil.showImageMid(data.getSendUserImg(), sdvHead2);
            //1-纯文本消息 2-图片消息 3-语音消息 4-评价
            switch (data.getMsgType()) {
                case 1:
                    tvMsg1.setVisibility(View.GONE);
                    tvMsg2.setVisibility(View.VISIBLE);
                    sdvImg1.setVisibility(View.GONE);
                    sdvImg2.setVisibility(View.GONE);
                    layout3.setVisibility(View.GONE);
                    tvMsg2.setText(data.getContent());
                    break;
                case 2:
                    tvMsg1.setVisibility(View.GONE);
                    tvMsg2.setVisibility(View.GONE);
                    sdvImg1.setVisibility(View.GONE);
                    sdvImg2.setVisibility(View.VISIBLE);
                    FrescoUtil.showImageSmall(data.getContent(), sdvImg2);
                    layout3.setVisibility(View.GONE);
                    break;
                case 3:
                    break;
                case 4:
                    tvMsg1.setVisibility(View.GONE);
                    tvMsg2.setVisibility(View.GONE);
                    sdvImg1.setVisibility(View.GONE);
                    sdvImg2.setVisibility(View.GONE);
                    layout3.setVisibility(View.VISIBLE);
                    break;

            }
        } else {
            layout1.setVisibility(View.VISIBLE);
            layout2.setVisibility(View.GONE);
            tvTime1.setText(data.getCreateTime());
            FrescoUtil.showImageMid(data.getSendUserImg(), sdvHead1);


            //1-纯文本消息 2-图片消息 3-语音消息 4-评价
            switch (data.getMsgType()) {
                case 1:
                    tvMsg1.setVisibility(View.VISIBLE);
                    tvMsg2.setVisibility(View.GONE);
                    sdvImg1.setVisibility(View.GONE);
                    sdvImg2.setVisibility(View.GONE);
                    layout3.setVisibility(View.GONE);
                    tvMsg1.setText(data.getContent());

                    break;
                case 2:
                    sdvImg1.setVisibility(View.VISIBLE);
                    sdvImg2.setVisibility(View.GONE);
                    tvMsg1.setVisibility(View.GONE);
                    tvMsg2.setVisibility(View.GONE);
                    FrescoUtil.showImageSmall(data.getContent(), sdvImg2);
                    layout3.setVisibility(View.GONE);

                    break;
                case 3:
                    break;
                case 4:
                    tvMsg1.setVisibility(View.GONE);
                    tvMsg2.setVisibility(View.GONE);
                    sdvImg1.setVisibility(View.GONE);
                    sdvImg2.setVisibility(View.GONE);
                    layout3.setVisibility(View.VISIBLE);
                    break;

            }
        }


        sdvImg1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                GotoUtil.gotoActivity((Activity) getContext(), ImageViewActivity.class, "img_url", JointImageUrl.imageUrl(data.getContent()));
            }
        });
        sdvImg2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                GotoUtil.gotoActivity((Activity) getContext(), ImageViewActivity.class, "img_url", JointImageUrl.imageUrl(data.getContent()));
            }
        });
        layout3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (UserXML.getUserId(getContext()).equals(data.getSendUser()) || mainCosultVO.getIsEvaluate() == 1) {
                    GotoUtil.gotoActivity((Activity) getContext(), ConsultEvaluateDetailActivity.class, "consultSessionId", mainCosultVO.getId());
                } else {
                    GotoUtil.gotoForResultActivity((Activity) getContext(), ConsultEvaluateAddActivity.class, 89,"consultSessionId", mainCosultVO.getId());
                }

            }
        });


    }

}
